package com.david.core.event;

import java.lang.reflect.Method;
import java.util.Objects;

/**
 * 每个订阅事件信息类
 * */
class SubscriberMethod {
    /**订阅回调的方法*/
     Method method;
    /**回调执行线程信息*/
    ThreadMode threadMode;
    /**订阅者，调用{@link com.david.core.event.MyEventBus#register(Object)}的方法的类*/
    Object subscriber;

    public SubscriberMethod() {
    }

    public SubscriberMethod(Method method, ThreadMode threadMode, Object subscriber) {
        this.method = method;
        this.threadMode = threadMode;
        this.subscriber = subscriber;
    }

    public Method getMethod() {
        return method;
    }

    public void setMethod(Method method) {
        this.method = method;
    }

    public ThreadMode getThreadMode() {
        return threadMode;
    }

    public void setThreadMode(ThreadMode threadMode) {
        this.threadMode = threadMode;
    }

    public Object getSubscribeObject() {
        return subscriber;
    }

    public void setSubscribeObject(Object subscribeObject) {
        this.subscriber = subscribeObject;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof SubscriberMethod)) return false;
        SubscriberMethod that = (SubscriberMethod) o;
        return Objects.equals(getMethod(), that.getMethod()) &&
                getThreadMode() == that.getThreadMode() &&
                Objects.equals(subscriber, that.subscriber);
    }

    @Override
    public int hashCode() {
        return Objects.hash(getMethod(), getThreadMode(), subscriber);
    }
}
